﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.LIB;
using YJKCopyModel.AxisTransModel;

namespace YJKCopyModel.Forms
{
	public partial class AxisModelTransForm : System.Windows.Forms.Form
	{
		public AxisModelTransForm(AxisModelRequestMaker maker, List<string> lstGridType)
		{
			this.InitializeComponent();
			this.m_strSelectGridType = string.Empty;
			this.m_lstAxisLineLayer = new List<string>();
			this.m_lstAxisNumberLayer = new List<string>();
			this.m_DlgCloseType = AxisModelTransForm.CloseDlgType.RT_Otheer;
			this.m_lstGridType = lstGridType;
			this.m_maker = maker;
			this.m_btnToolTip = new ToolTip();
			this.m_btnToolTip.AutomaticDelay = 500;
		}

		public AxisModelTransForm.CloseDlgType DlgCloseType
		{
			get
			{
				return this.m_DlgCloseType;
			}
		}

		public string SelectGridType
		{
			get
			{
				return this.m_strSelectGridType;
			}
		}

		public List<string> AxisLineLayers
		{
			get
			{
				return this.m_lstAxisLineLayer;
			}
		}

		public List<string> AxisNumberLayers
		{
			get
			{
				return this.m_lstAxisNumberLayer;
			}
		}

		public bool AddAxisTypeLayer(string strLayer)
		{
			bool flag = string.IsNullOrWhiteSpace(strLayer) || this.m_lstAxisLineLayer.Contains(strLayer);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this.m_lstAxisLineLayer.Add(strLayer);
				string text = "已选择图层：\n";
				for (int i = 0; i < this.m_lstAxisLineLayer.Count; i++)
				{
					text = text + this.m_lstAxisLineLayer[i] + "\n";
				}
				this.m_btnToolTip.SetToolTip(this.btnSelectAxisLine, text);
				result = true;
			}
			return result;
		}

		public bool AddAxisNumberLayer(string strLayer)
		{
			bool flag = string.IsNullOrWhiteSpace(strLayer) || this.m_lstAxisNumberLayer.Contains(strLayer);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this.m_lstAxisNumberLayer.Add(strLayer);
				string text = "已选择图层：\n";
				for (int i = 0; i < this.m_lstAxisNumberLayer.Count; i++)
				{
					text = text + this.m_lstAxisNumberLayer[i] + "\n";
				}
				this.m_btnToolTip.SetToolTip(this.btnSelectAxisNumber, text);
				result = true;
			}
			return result;
		}

		private void SetFormItemStyle()
		{
			this.labelSelectedAxisLine.Text = string.Format("已选择 {0} 个参考图元", this.m_lstAxisLineLayer.Count);
			this.labelSelectedAxisNumber.Text = string.Format("已选择 {0} 个参考图元", this.m_lstAxisNumberLayer.Count);
			this.pictSelectAxisLineOk.Visible = (this.m_lstAxisLineLayer.Count > 0);
			this.pictSelectAxisNumberOk.Visible = (this.m_lstAxisNumberLayer.Count > 0);
			this.labelSelectedAxisLine.ForeColor = ((this.m_lstAxisLineLayer.Count > 0) ? System.Drawing.Color.Green : System.Drawing.Color.Black);
			this.labelSelectedAxisNumber.ForeColor = ((this.m_lstAxisNumberLayer.Count > 0) ? System.Drawing.Color.Green : System.Drawing.Color.Black);
			this.btnTransLevel.Enabled = (this.m_lstAxisLineLayer.Count > 0);
			this.btnTransLocal.Enabled = (this.m_lstAxisLineLayer.Count > 0);
		}

		private void InitAxisTypeComboBox()
		{
			this.cmbAxisType.Items.Clear();
			foreach (string item in this.m_lstGridType)
			{
				this.cmbAxisType.Items.Add(item);
			}
			bool flag = this.cmbAxisType.Items.Count > 0;
			if (flag)
			{
				this.cmbAxisType.SelectedIndex = 0;
				this.m_strSelectGridType = this.m_lstGridType[0];
			}
		}

		private void AxisModelTransForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.SetFormItemStyle();
			this.InitAxisTypeComboBox();
		}

		private void btnSelectAxisLine_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = AxisModelTransForm.CloseDlgType.RT_SelectAxisLine;
			base.DialogResult = DialogResult.OK;
		}

		private void btnSelectAxisNumbew_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = AxisModelTransForm.CloseDlgType.RT_SelectAxisNumber;
			base.DialogResult = DialogResult.OK;
		}

		private void pictClearAxisLine_Click(object sender, EventArgs e)
		{
			this.m_lstAxisLineLayer.Clear();
			this.m_maker.ClearSelectedAxisLine();
			this.m_btnToolTip.SetToolTip(this.btnSelectAxisLine, null);
			this.SetFormItemStyle();
		}

		private void pictClearAxisNumber_Click(object sender, EventArgs e)
		{
			this.m_lstAxisNumberLayer.Clear();
			this.m_maker.ClearSelectedAxisNumber();
			this.m_btnToolTip.SetToolTip(this.btnSelectAxisNumber, null);
			this.SetFormItemStyle();
		}

		private void btnTransLevel_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = AxisModelTransForm.CloseDlgType.RT_TransForLevel;
			this.m_strSelectGridType = this.m_lstGridType[this.cmbAxisType.SelectedIndex];
			base.DialogResult = DialogResult.OK;
		}

		private void btnTransLocal_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = AxisModelTransForm.CloseDlgType.RT_TransForLocal;
			this.m_strSelectGridType = this.m_lstGridType[this.cmbAxisType.SelectedIndex];
			base.DialogResult = DialogResult.OK;
		}

		private void AxisModelTransForm_KeyDown(object sender, KeyEventArgs e)
		{
			bool flag = e.KeyCode == Keys.Escape;
			if (flag)
			{
				base.DialogResult = DialogResult.Cancel;
			}
		}

		private string m_strSelectGridType;

		private List<string> m_lstGridType;

		private List<string> m_lstAxisLineLayer;

		private List<string> m_lstAxisNumberLayer;

		private AxisModelTransForm.CloseDlgType m_DlgCloseType;

		private AxisModelRequestMaker m_maker;

		private ToolTip m_btnToolTip;

		public enum CloseDlgType
		{
			RT_Otheer,
			RT_SelectAxisLine,
			RT_SelectAxisNumber,
			RT_TransForLevel,
			RT_TransForLocal
		}
	}
}
